package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Entity.Ticket;
import com.buaa.airticketbookingsystem.Service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
public class GetDetailController {
    @Autowired
    private TicketService ticketService;

    @PostMapping("/getTicketDetail")
    public Map<String, Object> getTicketDetail(@RequestBody Map<String, String> remap){
        String s_id = remap.get("s_id");
        String f_id = remap.get("f_id");
        Map<String, Object> resMap = new HashMap<>();
        String t_id = f_id+s_id;
        Ticket t = ticketService.getTicketById(t_id);
        if(t == null){
            resMap.put("res", false);
            resMap.put("message", "f_id或s_id传递错误");
        } else{
            resMap.put("res", true);
            resMap.put("message", "返回成功");
            resMap.put("ticket", t);
        }
        return resMap;
    }
}
